package com.example.gw_back_end.controller;

import com.example.gw_back_end.domain.PageParam;
import com.example.gw_back_end.domain.PageResult;
import com.example.gw_back_end.domain.Result;
import com.example.gw_back_end.domain.entities.MinioBucket;
import com.example.gw_back_end.service.provider.MinIOService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("minio")
public class MinioController {

    private final MinIOService minIOService;
    public MinioController(MinIOService minIOService) {
        this.minIOService = minIOService;
    }

    // 创建Minio存储桶
    @PostMapping("create_minio_bucket")
    public Result createMinioAccount() {
        String minioBucket = minIOService.createMinioBucket();
        if (minioBucket != null) {
            return Result.success(minioBucket);
        } else {
            return Result.error("Minio存储桶创建失败！");
        }
    }

    // 删除minio存储桶
    @DeleteMapping("delete_minio_bucket")
    public Result deleteMinioBucket(Integer minioBucketId) {
        if (minIOService.deleteBucket(minioBucketId)) {
            return Result.success();
        } else {
            return Result.error();
        }
    }

    // 获取Minio存储桶
    @GetMapping("get_minio_bucket")
    public Result getMinioBucket(Integer minioBucketId) {
        MinioBucket minioBucket = minIOService.getMinioBucket(minioBucketId);
        if (minioBucket != null) {
            return Result.success(minioBucket);
        } else {
            return Result.error("获取Minio存储桶失败，请稍后重试！");
        }
    }

    // 获取Minio存储桶列表
    @GetMapping("get_minio_bucket_list")
    public Result getMinioBucketList(PageParam pageParam) {
        PageResult<MinioBucket> minioBucketPageResult = minIOService.getMinioBucketList(pageParam);
        if (minioBucketPageResult != null) {
            return Result.success(minioBucketPageResult);
        } else {
            return Result.error();
        }
    }
}
